from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import wsgiref.handlers
import os

import forecastmodels

class Home(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        path = os.path.join(os.path.dirname(__file__), 'templates', self.__class__.__name__ + '.html')
        self.response.out.write(template.render(path, {}))
        
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        zip_code = self.request.get('txt_zip_code')
        forecasts = forecastmodels.get_forecasts_db(zip_code)
        path = os.path.join(os.path.dirname(__file__), 'templates', self.__class__.__name__ + '.html')
        self.response.out.write(template.render(path, {'forecasts': forecasts}))
        
mainapp = webapp.WSGIApplication([('/', Home)], debug=False)

if __name__ == '__main__':
    wsgiref.handlers.CGIHandler().run(mainapp)